<template>
  <div class="collect-page">
    <van-nav-bar fixed title="我的喜欢" />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ArticleItem v-for="item in list" :key="item.id" :item="item" />
    </van-list>
  </div>
</template>

<script>
import { getOpt } from '@/api/article'
export default {
  name: 'collect-page',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },
  methods: {
    async onLoad () {
      // // (1)ajax请求数据
      // const { data } = await getOpt(1)
      // console.log(data)
      // // (2)添加到数组最后面
      // this.list.push(...data.rows)
      // // (3)完成本次加载
      // this.loading = false
      // // (4)判断是否全部加载完毕 (如果接口没数据，默认返回一个空数组)
      // if (this.page === data.pageTotal || !data.rows.length) {
      //   this.finished = true
      // } else {
      //   this.page++
      // }
      const { data } = await getOpt(1, 10, this.page)
      this.list.push(...data.rows)
      this.loading = false
      console.log(data)
      if (data.rows.length === 0) {
        this.finished = true
      }
      this.page++
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
